package com.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.pojo.OrderSetting;
import com.health.service.OrderSettingService;
import com.health.vo.Result;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    /**
     * 校验预约日期
     */
    @GetMapping("/checkOrderDate")
    public Result checkOrderDate(@DateTimeFormat Date orderDate){
        //查询预约设置
        OrderSetting orderSetting=orderSettingService.checkOrderDate(orderDate);
        //如果预约设置不存在,返回消息
        if (orderSetting ==null){
            return new Result(false,"该预约日期尚未设置预约人数,不可预约");
        }
        //如果预约存在,但是预约人数已满,返回消息
        if (orderSetting.getNumber()<=orderSetting.getReservations()){
            return new Result(false,"该日期已预约满员,请选择其他日期");
        }

        //可成功预约
        return new Result(true,"预约成功");
    }
}
